﻿Public Class LogWriter
    Private m_mainForm As FormUI

    Public Sub New()
        Dim forms As FormCollection = Application.OpenForms
        For Each form As Form In forms
            If TypeOf form Is FormUI Then
                m_mainForm = form
            End If
        Next
    End Sub
    Public Sub writeToFormWindow(ByVal message As String)
        'call the public update sub to update the system log in a thread safe way
        m_mainForm.UpdateSystemLog(m_mainForm.txtSystemLog.Text & message & vbNewLine)
    End Sub

    Public Sub writeTotalTweets(ByVal currentTweets As Integer)
        Dim totalTweets As Integer
        totalTweets = CInt(m_mainForm.txtTotalTweets.Text) + currentTweets

        m_mainForm.UpdateTotalTweets(totalTweets)
    End Sub

    Public Sub writeTotalImages(ByVal currentImages As Integer)
        Dim totalImages As Integer
        totalImages = CInt(m_mainForm.txtTotalImages.Text) + currentImages

        m_mainForm.UpdateTotalImages(totalImages)
    End Sub

    Public Sub writeLatestTweetID(ByVal latestTweet As Decimal)
        m_mainForm.UpdateLatestTweet(latestTweet)
    End Sub

    Public Sub writeImagesDownloaded(ByVal imagesDownloaded As Integer)
        m_mainForm.updateTotalImagesDownloaded(imagesDownloaded.ToString())
    End Sub

End Class
